import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-03-30
 * Time: 14:44
 */
public class RedisDemoSet {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");

        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("sadd 和 smembers 使用");
            jedis.flushAll();

            jedis.sadd("key1","11","22","33");
            Set<String> result = jedis.smembers("key1");
            System.out.println("result: " + result);
        }*/


        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("sismember 使用");
            jedis.flushAll();

            jedis.sadd("key1","11","22","33");
           boolean result = jedis.sismember("key1","11");
            System.out.println("result: " + result);
        }*/


        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("scard 使用");
            jedis.flushAll();

            jedis.sadd("key1","11","22","33");
            long result = jedis.scard("key1");
            System.out.println("result: " + result);
        }*/


        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("spop 使用");
            jedis.flushAll();

            jedis.sadd("key1","11","22","33");
            String result = jedis.spop("key1");
            System.out.println("result: " + result);
        }*/

        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("sinter 使用");
            jedis.flushAll();

            jedis.sadd("key1","11","22","33");
            jedis.sadd("key2","11","22","44");
            Set<String> result = jedis.sinter("key1","key2");
            System.out.println("result: " + result);
        }*/

        try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("sinterstore 使用");
            jedis.flushAll();

            jedis.sadd("key1","11","22","33");
            jedis.sadd("key2","11","22","44");
            long result = jedis.sinterstore("key3","key1","key2");
            Set<String> result1 = jedis.smembers("key3");
            System.out.println("result: " + result);
            System.out.println("result1: " + result1);
        }
    }
}
